home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
CTControlPanel.cs
< prev
next >
Wrap
Text File
|
2005-06-02
|
6KB
|
224 lines
//CTControlPanel.cs
using System;
using System.Windows.Forms;
using System.Drawing;
using MyCustomControls;
public class CTControlPanel : Panel
{
/// <summary>
/// Required designer variable.
/// </summary>
//public System.Windows.Forms.Panel ctControlPanel;
private System.Windows.Forms.TrackBar[] tbar_SliceIndex;
private System.Windows.Forms.TextBox[] tbox_SliceIndex;
private bool isLinkedToScan;
private bool isLinkedToView;
private ViewPanel viewPanel;
private Scan scan;
private ScrollSlider ss_WindowLevel;
//TAKE THIS OUT
public Label lbl;
public CTControlPanel()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();
//add a resize callback
this.Resize += new EventHandler(CTControlPanel_Resize);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.BorderStyle = BorderStyle.Fixed3D;
tbar_SliceIndex = new TrackBar[3]; //trackbar for each ortho view
tbox_SliceIndex = new TextBox[3];//and accompanying textbox
//initialize the trackbars and textboxes
for(int i = 0; i < 3; i++)
{
tbar_SliceIndex[i] = new TrackBar();
tbar_SliceIndex[i].TickStyle = TickStyle.None;
tbar_SliceIndex[i].Scroll += new EventHandler(
Slider_Scrolled);
this.Controls.Add(tbar_SliceIndex[i]);
tbox_SliceIndex[i] = new TextBox();
tbox_SliceIndex[i].KeyUp += new KeyEventHandler(
TextBox_Changed);
this.Controls.Add(tbox_SliceIndex[i]);
}
//initialize the window level scroll slider
ss_WindowLevel = new ScrollSlider();
ss_WindowLevel.Stretch += new EventHandler(Window_Changed);
ss_WindowLevel.Scroll += new EventHandler(Level_Changed);
this.Controls.Add(ss_WindowLevel);
}
//link the control to an actual view
public void LinkToViewPanel(ViewPanel vp)
{
viewPanel = vp;
isLinkedToView = true;
for(int i = 0; i < 3; i++)
{
tbar_SliceIndex[i].MouseDown += new MouseEventHandler(
tbar_MouseDown);
tbar_SliceIndex[i].MouseUp += new MouseEventHandler(
tbar_MouseUp);
}
ss_WindowLevel.MouseDown += new MouseEventHandler(
tbar_MouseDown);
ss_WindowLevel.MouseUp += new MouseEventHandler(
tbar_MouseUp);
}
//link the control to a scan that has the index data
//in Scan.SliceIndex
public void LinkToScan(Scan s)
{
scan = s;
for(int i = 0; i < 3; i++)
{
tbar_SliceIndex[i].SetRange(0,scan.DimensionSize[i]-1);
tbar_SliceIndex[i].Value = scan.SliceIndex[i];
tbox_SliceIndex[i].Text = scan.SliceIndex[i].ToString();
ss_WindowLevel.Window = scan.Window/4000f;
ss_WindowLevel.Level = (scan.Level+2000)/4000f;
}
isLinkedToScan = true;
}
private void Slider_Scrolled(object sender, EventArgs e)
{
if(isLinkedToScan) // only process call back if there is
{ // a scan that the control links to
for(int i = 0; i < 3; i++) //figure out which slider
{ //made the callback
if(sender.Equals(tbar_SliceIndex[i]))
{ //found it
scan.SliceIndex[i] = tbar_SliceIndex[i].Value;
tbox_SliceIndex[i].Text =
tbar_SliceIndex[i].Value.ToString();
}
Application.DoEvents(); //update text box as scan is scrolled
}
if(isLinkedToView)
{
viewPanel.Refresh();
}
}
}
private void TextBox_Changed(object sender, KeyEventArgs e)
{
if(isLinkedToScan) // only process call back if there is
{ // a scan that the control links to
for(int i = 0; i < 3; i++) //figure out which Textbox
{ //made the callback
if(sender.Equals(tbox_SliceIndex[i]))
{ //found it
int sliceIndex;
//make sure the text is numeric
try
{
sliceIndex = Convert.ToInt32(
tbox_SliceIndex[i].Text);
}
catch
{
//if not set it back to what it was
tbox_SliceIndex[i].Text =
tbar_SliceIndex[i].Value.ToString();
break;
}
//make sure the value is in bounds
if(sliceIndex >= scan.DimensionSize[i])
{
sliceIndex = scan.DimensionSize[i]-1;
tbox_SliceIndex[i].Text = sliceIndex.ToString();
}
if(sliceIndex <= 0)
{
sliceIndex = 0;
tbox_SliceIndex[i].Text = sliceIndex.ToString();
}
//update slider and scan attributes
scan.SliceIndex[i] = sliceIndex;
tbar_SliceIndex[i].Value = sliceIndex;
}
}
if(isLinkedToView)
{
viewPanel.Refresh();
}
}
}
//resize the CT Control Panel
private void CTControlPanel_Resize(object sender, EventArgs e)
{
int cx = this.Width;
int cy = this.Height;
int tboxWidth = 40;
for(int i = 0; i < 3; i++)
{
tbar_SliceIndex[i].SetBounds(0,(int)(cy/4.0*i),
cx-tboxWidth,(int)(cy/4.0));
tbox_SliceIndex[i].SetBounds(cx-tboxWidth,(int)(cy/4.0*i),
tboxWidth,(int)(cy/4.0));
}
ss_WindowLevel.SetBounds(10,(int)(3*cy/4.0)+10,cx-20,(int)(cy/4.0)-20);
}
private void tbar_MouseDown(object sender, MouseEventArgs e)
{
viewPanel.mainSliceView.DrawQuality = DRAW_QUALITY.LOW;
}
private void tbar_MouseUp(object sender, MouseEventArgs e)
{
viewPanel.mainSliceView.DrawQuality = DRAW_QUALITY.HIGH;
viewPanel.Refresh();
}
private void Window_Changed(object sender, EventArgs e)
{
if(isLinkedToScan)
{
scan.Window = (int)(ss_WindowLevel.Window*4000f);
//lbl.Text = scan.Window + "," + scan.Level;
viewPanel.Refresh();
}
}
private void Level_Changed(object sender, EventArgs e)
{
if(isLinkedToScan)
{
scan.Level = (int)(ss_WindowLevel.Level*4000 - 2000);
//lbl.Text = scan.Window + "," + scan.Level;
viewPanel.Refresh();
}
}
#endregion
}